<template>
	<view>
<!-- 		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input v-model="searchValue" data-name="searchValue" name="searchValue" @focus="onChange"
					@blur="onSearch" :adjust-position="false" placeholder="请输入房屋编号" confirm-type="search"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-green shadow-blur round" @tap="onSearch">搜索</button>
			</view>
		</view> -->
		
		
		<view v-if="houseCarTypes.length>0">
			<view class="padding">房屋信息</view>
			<view class="cu-list menu">
				<view class="cu-item" v-for="(home, idx) in houseCarTypes" :key="idx" :label="home.id">
					<view class="content padding-tb-sm" is-link @click="chooseHome(home)">
						<view>
							<text class="cuIcon-clothesfill text-blue margin-right-xs"></text> {{home.houseName}}
						</view>
						<view class="text-gray text-sm">
							<text class="cuIcon-infofill margin-right-xs"></text> {{home.id}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-else>
			<no-data-page></no-data-page>
		</view>
		
	</view>
</template>

<script>
	import context from '../../lib/java110/Java110Context.js';
	const constant = context.constant;
	import noDataPage from '@/components/no-data-page/no-data-page.vue'
	export default {
		data() {
			return {
				appUserName: '',
				areaCode: '',
				searchValue: '',
				homeInfo:'',
				homeName: "",
				homeId:'',
				units: [],
				unitId: '',
				
				houseDetail:'',
				houseNum:'',
				houseCarTypes:''
				
			}
		},
		components: {
			noDataPage
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			let _that = this;
			context.onLoad(options);
			_that.chooseCar();
		},
		methods: {

			chooseHome: function(_home) {
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				uni.setStorageSync("haBindHouse", _home);
				prevPage.houseNum = _home.houseName;
				//console.log(e);
				uni.navigateBack({
					delta: 1
				});
			},
			
			// 查询已绑定的房屋
			chooseCar() {
				let commonUserNum = uni.getStorageSync("commonUser");
				this.phone = commonUserNum.phone; //小区id
				uni.request({
					url: constant.url.choiceHasHouse,
					header: context.getHeaders(),
					method: "GET",
					data: {
						phone: this.phone,
					},
					success: (res) => {
						this.houseCarTypes = res.data.result
					},
					fail: function(e) {
						wx.showToast({
							title: "服务器异常了",
							icon: 'none',
							duration: 2000
						});
					}
				});
			},
		}
	}
</script>

<style>

</style>
